package cn.initcap.authentication;

import cn.initcap.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

/**
 * 表单登录配置
 *
 * @author initcap
 * @date 2018/5/20 AM12:36
 */
@Component
public class FormAuthenticationConfig {

    @Autowired
    protected AuthenticationSuccessHandler initcapAuthenticationSuccessHandler;

    @Autowired
    protected AuthenticationFailureHandler initcapAuthenticationFailureHandler;

    public void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                //登录页面的配置
                .loginPage(SecurityConstants.DEFAULT_UNAUTHENTICATION_URL)
                //登录请求路径
                .loginProcessingUrl(SecurityConstants.DEFAULT_SIGN_IN_PROCESSING_URL_FORM)
                //成功处理器
                .successHandler(initcapAuthenticationSuccessHandler)
                //失败处理器
                .failureHandler(initcapAuthenticationFailureHandler);
    }

}
